$("#back").on("click", function() {
	$(window).attr('location', "./addresslist.html");
})


var perfix = "http://1.15.177.112:8080";

$("#commitBtn").on('click', function() {
	var nickname = $("#nickname").val();
	var telephone = $("#telephone").val();
	var addressDesc = $("#addressDesc").val();
	var postalCode = $("#postalCode").val();
	if ($("#isDefault").prop('checked')) {
		var isDefault = 0;
	} else {
		var isDefault = 1;
	}

	var model = {
		"nickname": nickname,
		"telephone": telephone,
		"addressDesc": addressDesc,
		"postalCode": postalCode,
		"isDefault": isDefault
	}

	$.ajax({
		url: perfix + "/address/add",
		data: JSON.stringify(model),
		type: 'post',
		headers: {
			'Authorization': localStorage.getItem("token")
		},
		contentType: 'application/json',
		success: function(data) {
			if (data.code == 10006) {
				localStorage.clear();
				$(window).attr('location', "login.html");
			}
			$(window).attr('location', "./addresslist.html");
		}
	})

})
